﻿<?php
/*********************************************************************\
* This File is a part of BH-PANEL (Breizh-Heberg Panel v2.1)
* Copyright (C) 2008-2009 the BH Developpers : Vincent Giersch <mail@vincordi.fr>, Cyprien Laleau <fanning.fr@gmail.com> and Edwin Cabiten <marmottes44@hotmail.fr>
* See file AUTHORS to get more informations

* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.

* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
/*********************************************************************/

$title = "Maintenances - Travaux";
$tplinc = "maintenances-index";
$parse = 1;


if (isset($_GET['cat']) && !empty($_GET['cat']))
{
	$cat = intval($_GET['cat']);
	$req = "SELECT * FROM maintenance WHERE categorie ='".$cat."' ORDER BY id DESC";
	$req_page = "SELECT COUNT(*) AS nb_maint FROM maintenance WHERE categorie ='".$cat."'";
}
else
{
	$cat = '0';
	$req = "SELECT * FROM maintenance ORDER BY id DESC";
	$req_page = "SELECT COUNT(*) AS nb_maint FROM maintenance";
}
$nombreDeMessagesParPage = 20; 
$retour = query($req_page);
$donnees = mysql_fetch_array($retour);
$totalDesMessages = $donnees['nb_maint'];
$nombreDePages  = ceil($totalDesMessages / $nombreDeMessagesParPage);

if (isset($_GET['p']) && !empty($_GET['p']))
{
	if (intval($_GET['p']) <= $nombreDePages)
	{
        $p = intval($_GET['p']); 
	}
	else
	{
		$p = 1;
	}	
}
else
{ 
    $p = 1;
}
	$premierMessageAafficher = ($p - 1) * $nombreDeMessagesParPage;
	
	$tpl->assign(array(	'nb_page' => $nombreDePages,
						'page_a' => $p,
						'page_p' => ($p - 1),
						'page_s' => ($p + 1),
						));



	$maint = query($req." LIMIT ".$premierMessageAafficher.", ".$nombreDeMessagesParPage."");
	
	
	$type_array = array(
						'1' => 'Maintenance',
						'2' => 'Mise à jour',
						'3' => 'Incident',
						'4' => 'Installation',
						);
							
	$severite_array = array('1' => 'Basse',
							'2' => 'Moyenne',
							'3' => 'Haute',
							'4' => 'Critique',
							);
								
	$etat_array = array('1' => 'Annuler',
						'2' => 'En cours',
						'3' => 'En pause',
						'4' => 'Terminé',
						);
							
	$cat_array = array( '0' => 'Général',
						'1' => 'Noms de domaine',
						'2' => 'Hébergement multualisé',
						'3' => 'Panel',
						'4' => 'Datacenter',
						);
						
	$fermer_array = array(	'0' => 'Non',
							'1' => 'Oui',
						);
						
	$priorite_array = array('1' => 'Normal',
							'2' => 'Flash',
							'3' => 'Immédiate',
							'4' => 'Urgente',
							);
							
	$title = "Maintenances - Travaux - ".$cat_array[$cat];
	$i=0;
	
	while ($result_maint = mysql_fetch_array($maint))
	{
		$i++;
		
		$titre = stripslashes($result_maint['titre']);
		$id = $result_maint['id'];
		$type = $result_maint['type'];
		$etat = $result_maint['etat'];
		$severite = $result_maint['level_severite'];
		$poucentage = $result_maint['pourcent_fini'];
		$cat_sql = $result_maint['categorie'];
		$date_o = $result_maint['date_ouvert'];
		$fermer = $result_maint['fermer'];
		$date_f = $result_maint['date_fermer'];
		$priorite = $result_maint['priorite'];
		$details = nl2br(stripslashes($result_maint['details']));
		
		$tpl->assign_array('aff_maint', array(
											'id_maint' => $id,
											'severite_maint' => $severite_array[$severite],
											'type_maint' => $type_array[$type],
											'titre_maint' => $titre,
											'etat_maint' => $etat_array[$etat],
											'no_severite_maint' => $severite,
											'progress_maint' => $poucentage,
											'cat_maint' => $cat_array[$cat_sql],
											'count' => strlen($id),
											'nb_html' => $i,
											'date_o' => $date_o,
											'fermer' => $fermer,
											'fermer_t' => $fermer_array[$fermer],
											'date_f' => $date_f,
											'priorite' => $priorite_array[$priorite],
											'details' => $details,
											));
	}
											
		$tpl->assign(array('i_max' => $i));
		
?>